/* MainFram.java 
* Created on Nov 29, 2012 
*@Author: Mr.Viet 
*@Phone: 01683430426 
*@Email: phamvanvietcdhd@gmail.com
*/ 
package com.session2; 

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import net.miginfocom.swing.MigLayout;

public class MainFram extends JFrame implements ActionListener{
	private JButton btnLogin;
	private JMenuBar menuBar;
	private JMenu mFile,mEdit,mView,mHelp,mStyle;
	private JMenuItem miOpen,miFont,miExit;
	private JCheckBoxMenuItem miBold,miItalic;
	
	public void createForm(){
		this.setLayout(new MigLayout());
		
		this.btnLogin = new JButton("Login");
		this.getContentPane().add(btnLogin);
		
//		Khoi Tao Thanh Phan JMenuBar
		this.menuBar = new JMenuBar();
		this.setJMenuBar(this.menuBar);
//		Khoi Tao Cac Thanh Phan JMenu
//		mFile
		this.mFile = new JMenu("File");
		this.miOpen = new JMenuItem("Open File");
		this.miExit = new JMenuItem("Exit");
		this.miExit.setMnemonic(KeyEvent.VK_E);
		this.miExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,KeyEvent.CTRL_MASK));
		
		this.mFile.add(this.miOpen);
		this.mFile.addSeparator();
		this.mFile.add(this.miExit);
		this.menuBar.add(this.mFile);
//		mEdit
		this.mEdit = new JMenu("Edit");
		this.miFont = new JMenuItem("Set Font");
		this.menuBar.add(this.mEdit);
		this.mEdit.add(this.miFont);
//		mView
		this.mView = new JMenu("View");
		this.mStyle = new JMenu("Style");
		this.miBold = new JCheckBoxMenuItem("Bold");
		this.miItalic = new JCheckBoxMenuItem("Italic");
		
		this.mStyle.add(this.miBold);
		this.mStyle.add(this.miItalic);
		this.mView.add(this.mStyle);
		this.menuBar.add(this.mView);
//		mHelp
		this.mHelp = new JMenu("Help");
		this.menuBar.add(this.mHelp);
//		Dang Ki Su Kien
		this.btnLogin.addActionListener(this);
	}
	public void showForm(){
		this.setTitle("Demo");
		this.setSize(800, 600);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public String getUsername(){
		return "abc";
	}
	public static void main(String[] args) {
		MainFram d = new MainFram();
		d.createForm();
		d.showForm();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == this.btnLogin){
			Jlogin l = new Jlogin();
			l.parentForm = this;
			l.createForm();
			l.setModal(true);
			l.showForm();
		}else if(e.getSource() == this.miExit){
			System.exit(0);
		}
	}
}
